package com.param_validate_demo.service;

import com.param_validate_demo.mapper.TaskMapper;
import com.param_validate_demo.model.Task;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

@Service
public class TaskService {

    @Autowired
    private TaskMapper taskMapper;

    public BigInteger addExportTask() {
        Task task = new Task();
        task.setType("导出");
        task.setStatus("未执行");
        taskMapper.insert(task);
        return task.getId();
    }

    public void updateExportTask(Task entity) {
        taskMapper.updateById(entity);
    }

    public List<Task> getTopTenExportTask() {
        QueryWrapper<Task> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        Page<Task> page = taskMapper.selectPage(new Page<>(1, 10), wrapper);
        return page.getRecords();
    }
}
